package WordCount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author 姜世钰
 * date: 2021/9/29 15:32
 **/
public class WordCountMain {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
       //创建一个job和任务入口
        Job job = Job.getInstance(new Configuration());
        job.setJarByClass(WordCountMain.class);

        job.setMapperClass(WordCountMapper.class);//指定Mapper类
        job.setMapOutputKeyClass(Text.class);    //k2的类型
        job.setMapOutputValueClass(IntWritable.class);  //v2的类型

        //3.指定job的reducer和输出的类型<k4  v4>
        job.setReducerClass(WordCountReducer.class);//指定Reducer类
        job.setOutputKeyClass(Text.class);  //k4的类型
        job.setOutputValueClass(IntWritable.class);  //v4的类型

        //4.指定job的输入和输出
        FileInputFormat.setInputPaths(job, new Path(args[0]));//args[0]指的是第一个参数
        FileOutputFormat.setOutputPath(job, new Path(args[1]));//args[1]指的是第二个参数

        //5.执行job
        job.waitForCompletion(true);

    }
}
